{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-04T03:41:54.863710Z",
     "start_time": "2025-09-04T03:41:54.859763Z"
    }
   },
   "source": [
    "import torch\n",
    "import torchvision.datasets\n",
    "from torch.nn import MaxPool2d\n",
    "from torch.utils.tensorboard import SummaryWriter\n",
    "from torchvision import transforms\n",
    "from torch.utils.data import DataLoader\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F"
   ],
   "outputs": [],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-04T03:41:55.564300Z",
     "start_time": "2025-09-04T03:41:54.889647Z"
    }
   },
   "cell_type": "code",
   "source": [
    "test_data = torchvision.datasets.CIFAR10(root='./dataset', train=False, download=True, transform=transforms.ToTensor())\n",
    "dataloader = DataLoader(test_data, batch_size=64, shuffle=True)"
   ],
   "id": "8ab870773863dcbd",
   "outputs": [],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-04T03:45:45.543981Z",
     "start_time": "2025-09-04T03:45:45.536481Z"
    }
   },
   "cell_type": "code",
   "source": [
    "class MultiLayerDemo(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(MultiLayerDemo, self).__init__()\n",
    "        self.maxPool = MaxPool2d(kernel_size=3, ceil_mode=True)\n",
    "        self.relu = nn.ReLU()\n",
    "        self.sigmod = nn.Sigmoid()\n",
    "        self.softmax = nn.Softmax(dim=1)\n",
    "\n",
    "    def forward(self, x):\n",
    "        # x = self.maxPool(x)\n",
    "        # x = self.relu(x)\n",
    "        x = self.sigmod(x)\n",
    "        return x\n",
    "\n",
    "model = MultiLayerDemo()\n",
    "print(model)"
   ],
   "id": "1d392837cd4cf46b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MultiLayerDemo(\n",
      "  (maxPool): MaxPool2d(kernel_size=3, stride=3, padding=0, dilation=1, ceil_mode=True)\n",
      "  (relu): ReLU()\n",
      "  (sigmod): Sigmoid()\n",
      "  (softmax): Softmax(dim=1)\n",
      ")\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-04T03:45:55.237771Z",
     "start_time": "2025-09-04T03:45:48.367233Z"
    }
   },
   "cell_type": "code",
   "source": [
    "writer = SummaryWriter(\"./logs\")\n",
    "step = 0\n",
    "\n",
    "for data in dataloader:\n",
    "    imgs, labels = data\n",
    "    out_imgs = model(imgs)\n",
    "    # writer.add_images(\"maxPool-input\", imgs, step)\n",
    "    # writer.add_images(\"maxPool-output\", out_imgs, step)\n",
    "    # writer.add_images(\"relu-input\", imgs, step)\n",
    "    # writer.add_images(\"relu-output\", out_imgs, step)\n",
    "    writer.add_images(\"sigmoid-input\", imgs, step)\n",
    "    writer.add_images(\"sigmoid-output\", out_imgs, step)\n",
    "\n",
    "    step += 1\n",
    "\n",
    "writer.close()\n"
   ],
   "id": "a17ebcaac1bd9298",
   "outputs": [],
   "execution_count": 13
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
